package com.bigflexlib.ds.op
{
	import flexunit.framework.TestCase;
	
	import com.bigflexlib.ds.container.zet.IOWSet;
	import com.bigflexlib.ds.container.zet.IRWSet;
	import com.bigflexlib.ds.container.zet.impl.owSet;
	import com.bigflexlib.utils.IOperator;

	public class ContainerBiggestOpTest extends TestCase
	{


		private var currentBiggestElement:*;


		public function test_findBiggest( ):void
		{
			
			
			var biggest:*;
			
			var zet:IRWSet = owSet( ["a","b","c"] );
			
			biggest = ContainerBiggestOp.findBiggest( zet, nativeCompare );		
						
			assertEquals( biggest, "c" );
		
			biggest = ContainerBiggestOp.findBiggest( zet, nativeCompare, "d" );		
		
			assertEquals( biggest, "d" );
			
		
		}
		
		
		
		public function testMisc( ):void
		{
		
			var zet:IOWSet = owSet( [ "a", "b", "c" ] );
			
			var op:IOperator = new ContainerBiggestOp( zet, nativeCompare, handleValue, "" );
			
			assertEquals( currentBiggestElement, "c" );
			

			zet.add( "e" );
			assertEquals( currentBiggestElement, "e" );
			

			zet.add( "d" );
			assertEquals( currentBiggestElement, "e" );
				

			zet.remove( "e" );
			assertEquals( currentBiggestElement, "d" );
		
			
			zet.clear( );
			assertEquals( currentBiggestElement, "" );
		
			
			zet.autoUpdateFlag.disable( );
			
				zet.add( "a" );
				zet.add( "b" );
				
				assertEquals( currentBiggestElement, "" );
		
			zet.autoUpdateFlag.enable( );
		
			assertEquals( currentBiggestElement, "b" );
		
		
		
		}
		
		
		
		
		
		
		
		
		private function handleValue( e:* ):void
		{
			currentBiggestElement = e;
		}
		
		
		
		private function nativeCompare( a:*, b:* ):int
		{
			if ( a > b )
				return 1;
			
			if ( a < b )
				return -1;
			
			return 0;
		}
		
		
	}

}